package com.fh.controller;

import com.alibaba.nacos.shaded.org.checkerframework.checker.units.qual.A;
import com.fh.feign.Demo3Feign;
import com.fh.utils.annotation.NeedToken;
import com.fh.utils.annotation.PassToken;
import com.fh.utils.swagger.SwaggerProperties;
import com.utils.bean.*;
import com.utils.pulc.ResultBody;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Map;

/**
 * @author whf
 * @date 2023年05月11日 13:32
 */
@Api(tags = "小Demo")
@RequestMapping("demo3")
@RestController
public class Demo3Controller {

    @Autowired
    private Demo3Feign demo3Feign;

    /**
     * @description: 登录接口 如果密码正确则会登录并且查出他的信息
     * @author whf
     * @date 2023/5/10 14:21
     * @param safety
     * @return com.utils.pulc.ResultBody<com.utils.bean.User>
     */
    @ApiOperation("登录接口")
    @PassToken
    @PostMapping("index")
    public ResultBody<User> index(@Valid @RequestBody Safety safety){
        return demo3Feign.index(safety);
    }

    /**
     * @description: 注册接口
     * @author whf
     * @date 2023/5/10 15:07
     * @param safetyAndUser
     */
    @ApiOperation("注册接口")
    @PassToken
    @PostMapping("setSafetyAndUser")
    public ResultBody<Object> setSafetyAndUser(@Valid @RequestBody SafetyAndUser safetyAndUser){
        demo3Feign.setSafetyAndUser(safetyAndUser);
        return ResultBody.ok();
    }

    /**
     * @description: 根据登录用户的id 查询权限
     * @author whf
     * @date 2023/4/25 15:03
     * @param substitute
     * @return com.fh.utils.ResultBody<java.lang.Object>
     */
    @ApiOperation("查询权限")
    @NeedToken
    @PostMapping("selectAll")
    public ResultBody<List<Role>> selectAll(@RequestBody Substitute substitute) {
        return demo3Feign.selectAll(substitute);
    }

    /**
     * @description: 退出登录
     * @author whf
     * @date 2023/5/10 15:52
     * @param substitute
     * @return com.utils.pulc.ResultBody<java.lang.Object>
     */
    @ApiOperation("退出登录")
    @NeedToken
    @PostMapping("exit")
    public ResultBody<String> exit(@RequestBody Substitute substitute){
        return demo3Feign.exit(substitute);
    }

    /**
     * @description: 分页查询
     * @author whf
     * @date 2023/5/17 9:38
     * @param customerPage
     * @return com.utils.pulc.ResultBody<java.util.List<com.utils.bean.Customer>>
     */
    @ApiOperation("分页查询")
    @NeedToken
    @PostMapping("page")
    public ResultBody<List<Customer>> getCustomerPage(@Valid @RequestBody CustomerPage customerPage){
        return demo3Feign.getCustomerPage(customerPage);
    }
    /**
     * @description: 添加客户信息
     * @author whf
     * @date 2023/5/11 15:08
     * @param customer
     * @return com.utils.pulc.ResultBody<java.lang.Object>
     */
    @ApiOperation("添加客户信息")
    @NeedToken
    @PostMapping("save")
    public ResultBody<Object> save(@RequestBody Customer customer){
        return demo3Feign.save(customer);
    }


    /**
     * @description: 对他的ID进行删除
     * @author whf
     * @date 2023/5/17 9:20
     * @param
     * @return null
     */
    @ApiOperation("对他的ID进行删除")
    @NeedToken
    @PostMapping("delCostomer")
    public ResultBody<Object> delCostomer(@RequestBody CostomerID costomerID){
        return ResultBody.ok(demo3Feign.delCostomer(costomerID));
    }
    /**
     * @description: 对一群人进行删除
     * @author whf
     * @date 2023/5/17 9:22
     * @param
     * @return com.utils.pulc.ResultBody<java.lang.Object>
     */
    @ApiOperation("对一群人进行删除")
    @NeedToken
    @PostMapping("delCostomers")
    public ResultBody<Object> delCostomers(@RequestBody List<CostomerID> costomerIDS){
        return ResultBody.ok(demo3Feign.delCostomers(costomerIDS));
    }

    /**
     * @description: 根据条件查询
     * @author whf
     * @date 2023/5/17 10:42
     * @param customer
     * @return com.utils.pulc.ResultBody<java.util.List<com.utils.bean.Customer>>
     */
    @ApiOperation("根据条件查询")
    @NeedToken
    @PostMapping("getCustomerIF")
    public ResultBody<List<Customer>> getCustomerIF(@RequestBody Customer customer){
        System.out.println(customer.toString());
        return demo3Feign.getCustomerIF(customer);
    }

    /**
     * @description: 保存图片
     * @author whf
     * @date 2023/5/31 9:03
     * @param multipartFile
     * @return com.utils.pulc.ResultBody<java.util.List<java.lang.String>>
     */

    @NeedToken
    @PostMapping(value = "setMultipartFile",  consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    @ApiOperation(value = "文件上传", notes = "返回数据：文件相对路径；请求方式：multipart/form-data")
    public ResultBody<String> setMultipartFile(@RequestPart MultipartFile multipartFile,@RequestParam(defaultValue = "Id不能为空") Integer id){
        return demo3Feign.setMultipartFile(new MultipartFileImag(multipartFile,id));
    }

    /**
     * @description: 对保存的图片地址进行查询
     * @author whf
     * @date 2023/6/1 15:11
     * @param imagesOrUser
     * @return java.util.List<java.lang.String>
     */
    @PostMapping("getImage")
    @NeedToken
    @ApiOperation("对保存的图片地址进行查询")
    public ResultBody<List<Photograph>> getImage(@RequestBody @Valid ImagesOrUser imagesOrUser){
        return demo3Feign.getImage(imagesOrUser);
    }


    /**
     * @param imagesUpdate
     * @return com.utils.pulc.ResultBody<java.lang.Object>
     * @description: 对图片进行删除
     * @author whf
     * @date 2023/6/1 17:23
     */

    @PostMapping("updateImages")
    @NeedToken
    @ApiOperation("对图片进行删除")
    public ResultBody<Object> updateImages(@RequestBody ImagesUpdate imagesUpdate){
        demo3Feign.updateImages(imagesUpdate);
        return ResultBody.ok();
    }


    @PostMapping("updateMoney")
    @ApiOperation("钱财")
    @PassToken
    public ResultBody<Object> updateMoney(@RequestBody MoneyAll money){
        demo3Feign.updateMoney(money);
        return ResultBody.ok();
    }

}
